
             
/**
 * 
 *
 * @File name:  BatchDeleteTCheckInfoDetailAction.java   批量删除【盘点明细:T_CHECK_INFO_DETAIL】
 * @Create on:  2011-12-04 13:09:140
 * @Author   :  许福辉
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        
package com.boho.estates.usual.action;

            
import java.sql.Connection;
import java.util.Date;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.MessageService;

import com.boho.base.dao.DaoHelper;
import com.boho.common.Constant;
import com.boho.common.SystemUtils;
import com.boho.estates.po.TCheckInfoDetailPO;
import com.boho.estates.po.TCheckInfoLogPO;
            
        

public class BatchCheckTCheckInfoDetailAction extends ActionImp {
	private Object[] id;
	private Connection con=null;
	private String check_no = "";
	private int is_check=1;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("EC_COMMON_1003", MessageService.getMessage("EC_COMMON_1003"),"【盘点明细】", ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		if(id!=null){
			String createBy = SystemUtils.getSessionUser(atx);
			//用户所属部门
			DynaBeanMap useesion =(DynaBeanMap)atx.getSessionValue(Constant.SESSION_PERSON_BEAN);
			if(useesion==null||useesion.get("DEPARTMENT_NO")==null)
			{
				UserOperationException uoe = new UserOperationException();
				atx.setErrorContext("ESTATES_USUAL_1004", MessageService.getMessage("ESTATES_USUAL_1004"),uoe);
				throw uoe;
			}
			//DaoHelper.setTDepartmentField(con, useesion, "", "DEPARTMENT_NO");
			for (int i = 0; i < id.length; i++) {
				String[] idAndBarcode = id[i].toString().split("-");
				TCheckInfoDetailPO tCheckInfoDetailPO = new TCheckInfoDetailPO();
				TCheckInfoDetailPO vCheckInfoDetailPO = new TCheckInfoDetailPO();
				tCheckInfoDetailPO.setId(idAndBarcode[0]==null||idAndBarcode[0].toString().trim().equals("")?-1:new Integer((String)idAndBarcode[0]));
				vCheckInfoDetailPO.setIsCheck(is_check);
				vCheckInfoDetailPO.setCheckPerson(useesion.get("NAME").toString());
				vCheckInfoDetailPO.setCheckDemp(useesion.get("DEPARTMENT_NO").toString());
				vCheckInfoDetailPO.setCheckDate(new java.util.Date());
				vCheckInfoDetailPO.setUpdateBy(createBy);
				vCheckInfoDetailPO.setUpdateDate(new java.util.Date());
				POUtils.update(con, tCheckInfoDetailPO, vCheckInfoDetailPO, false);
				
				TCheckInfoLogPO tchekLog =new TCheckInfoLogPO();
				tchekLog.setBarcode(idAndBarcode[1]);
				tchekLog.setCheckNo(check_no);
				tchekLog.setCheckPerson(useesion.get("NAME").toString());
				tchekLog.setCheckDemp(useesion.get("DEPARTMENT_NO").toString());
				tchekLog.setCreateBy(createBy);
				tchekLog.setCreateDate(new java.util.Date());
				POUtils.insert(con, tchekLog,false);
			}
		}
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		con = atx.getConection();
		id = atx.getArrayValue("ID");
		check_no = atx.getStringValue("CHECK_NO","-1");
		is_check = atx.getIntegerValue("IS_CHECK", 1);
		return 1;
	}
}
